<?php
namespace gnomephp\form;

class Captcha extends FormField{
	
	protected $width = 120;
	protected $height = 30;
	
	
	/**
	 * Sets the scale of the captcha. See also setDimension.
	 * Scale is more convenient to use for captcha generaiton so this method is prefered.
	 * @param int $scale , sets a scale based on int / float value. 4 = 120 width, 30 height.
	 */
	public function setScale($scale){
		$this->width = $scale * 30;
		$this->height = $scale * 7.5;
		return $this;
	}
	
	/**
	 * Sets dimension of the captcha image.
	 * @param int $width Width amount in pixles.
	 * @param int $height Height amount in pixles.
	 */
	public function setDimension($width, $height){
		$this->width = $width;
		$this->height = $height;
		return $this;
	}
	
	
	public function __construct($formId, $url, $name, $value, $props){
		parent::__construct($formId, $url, $name, $value, $props);

	}
	public function __toString(){
		return '<img src='.$this->url->linkTo('captcha', 
				array(
				'name' => $this->name, 
				'width' => $this->width, 
				'height' => $this->height
				)
			).' alt="'.$this->value.'"'.$this->buildProps($this->props).' />';
	}
	
	/**
	 * Gets a Input box that works with the captcha image. This is of type text.
	 * @param string $value Default value.
	 * @param array $props Custom Properties.
	 */
	public function getInput($value=null, $props=array()){
		return new Input($this->id, $this->url, $this->name, $value, $props, 'text');
	}
	
}